//
//  ZM_BigImg_CVCell.m
//  YYFMMall
//
//  Created by MAC on 2019/12/11.
//  Copyright © 2019 YuYou1. All rights reserved.
//

#import "ZM_BigImg_CVCell.h"

@implementation ZM_BigImg_CVCell

-(void)setImgUrl:(NSString *)imgUrl{
    _imgUrl = imgUrl;
    [self.imgV sd_setImageWithURL:kURL(imgUrl) placeholderImage:kImage(KDefBannerIcon)];
}

-(void)setImgCornerRadius:(CGFloat)imgCornerRadius{
    _imgCornerRadius = imgCornerRadius;
    [ZMSpeedy zm_changeControl:self.imgV cornerRadius:imgCornerRadius borderWidth:0 borderColor:nil mask:YES];
}

-(void)setIsShowBtn:(CGFloat)isShowBtn{
    _isShowBtn = isShowBtn;
    self.iconBtn.hidden = !isShowBtn;
}

#pragma mark - Methods


-(void)tapImgVAction{
    !self.tapImgVBlock?:self.tapImgVBlock(self.imgV);
}

-(void)iconBtnAction:(UIButton *)sender{
    !self.iconBtnBlock?:self.iconBtnBlock();
}

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpBaseData];
        [self setUpUI];
    }
    return self;
}

///基本数据设置
-(void)setUpBaseData{
    
}

///添加控件
-(void)setUpUI{
    [self bgV];
    [self imgV];
    [self iconBtn];
}

#pragma mark - lazyLoad

-(UIImageView *)imgV{
    if (!_imgV) {
        _imgV = [UIImageView new];
        _imgV.contentMode = UIViewContentModeScaleAspectFill;
        _imgV.layer.masksToBounds = YES;
        _imgV.userInteractionEnabled = YES;
        [self addSubview:_imgV];
        [_imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.top.mas_equalTo(3);
            make.bottom.mas_equalTo(-3);
        }];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImgVAction)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        [_imgV addGestureRecognizer:tap];
    }
    return _imgV;
}

-(UIButton *)iconBtn{
    if (!_iconBtn) {
        _iconBtn = [UIButton new];
        UIImage *img = kImage(@"news_playbtn");
        [_iconBtn setBackgroundImage:img forState:UIControlStateNormal];
        _iconBtn.touchAreaInsets = UIEdgeInsetsMake(30, 30, 30, 30);
        _iconBtn.hidden = YES;
        [self addSubview:_iconBtn];
        BlockSelf(img);
        [_iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(self);
            make.size.mas_equalTo(blockimg.size);
        }];
        
        [_iconBtn addTarget:self action:@selector(iconBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _iconBtn;
}

-(UIView *)bgV{
    if (!_bgV) {
        _bgV = [UIView new];
        _bgV.hidden = YES;
        _bgV.backgroundColor = kHexColor(0xFAFAFA);
        [self addSubview:_bgV];
        [_bgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.bottom.top.mas_equalTo(0);
        }];
    }
    return _bgV;
}
@end
